package org.marsdonne.common.test;

import graphql.kickstart.tools.GraphQLMutationResolver;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.stereotype.Component;

import javax.servlet.http.Part;
import java.io.IOException;
import java.util.List;

@Component
public class SampleMutationResolver implements GraphQLMutationResolver {

    public String doSomeThings(Long id, List<Part> parts, DataFetchingEnvironment dataFetchingEnvironment) throws IOException {
        List<Part> uploads = dataFetchingEnvironment.getArgument("uploads");
        int size = uploads.get(0).getInputStream().available();
        return "The size of uploaded file numbered " + id + " is " + size + " b";
    }
}
